package com.wanmait.wisdom.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.wisdom.entity.Complaint;
import com.wanmait.wisdom.manage.service.ManageComplaintService;
import com.wanmait.wisdom.mapper.ComplaintMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class ManageComplaintServiceImpl extends ServiceImpl<ComplaintMapper, Complaint> implements ManageComplaintService {
    @Resource
    private ComplaintMapper complaintMapper;

    @Override
    public List<Complaint> selectAllComplaints() {
        List<Complaint> complaintList =  complaintMapper.selectAllComplaints();
        return complaintList;
    }

    @Override
    public Complaint selectComplaintById(Integer id) {
        Complaint complaint =  complaintMapper.selectByID(id);
        return complaint;
    }

    @Override
    public Long getComplaintFinishedCount() {
        QueryWrapper<Complaint> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("processing_status",1);
        return complaintMapper.selectCount(queryWrapper);
    }

    @Override
    public Long getComplaintUnFinishedCount() {
        QueryWrapper<Complaint> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("processing_status",0);
        return complaintMapper.selectCount(queryWrapper);
    }

    @Override
    public PageInfo<Complaint> searchComplaintByCondition(Complaint complaint, Integer pageNum, Date startTime, Date endTime, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        System.out.println(complaint.getProcessingStatus());
        return new PageInfo<>(complaintMapper.searchComplaintByCondition(complaint,startTime,endTime));
    }
}
